﻿using CarLeasing.Data;
using CarLeasing.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CarLeasing.Forms
{
    public partial class FavoritesForm : Form
    {
        public FavoritesForm()
        { }

        public FavoritesForm(User user, LocalStore store)
        {
            User = user;
            Store = store;
            InitializeComponent();
        }

        private void FavoritesForm_Load(object sender, EventArgs e)
        {
            button_Back.Click += (s, _) => Close();
            carInfoListPanel.CarSelected += car => SelectedCar = car;
            carInfoListPanel.LoadCarInfos(User.Favorites(Store));
        }

        private void button_Remove_Click(object sender, EventArgs e)
        {
            if (SelectedCar == null)
                return;

            User.RemoveFavorite(SelectedCar, Store);
            SelectedCar = null;
            carInfoListPanel.LoadCarInfos(User.Favorites(Store));
        }

        private CarInfo SelectedCar;
        private readonly User User;
        private readonly LocalStore Store;
    }
}
